<!DOCTYPE HTML>
<html lang="en" class="light" dir="ltr">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>Overrides - The rustup book</title>


        <!-- Custom HTML head -->
        
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff">

        <link rel="icon" href="favicon.svg">
        <link rel="shortcut icon" href="favicon.png">
        <link rel="stylesheet" href="css/variables.css">
        <link rel="stylesheet" href="css/general.css">
        <link rel="stylesheet" href="css/chrome.css">
        <link rel="stylesheet" href="css/print.css" media="print">

        <!-- Fonts -->
        <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
        <link rel="stylesheet" href="fonts/fonts.css">

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->

    </head>
    <body class="sidebar-visible no-js">
    <div id="body-container">
        <!-- Provide site root to javascript -->
        <script>
            var path_to_root = "";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script>
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script>
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('light')
            html.classList.add(theme);
            var body = document.querySelector('body');
            body.classList.remove('no-js')
            body.classList.add('js');
        </script>

        <input type="checkbox" id="sidebar-toggle-anchor" class="hidden">

        <!-- Hide / unhide sidebar before it is displayed -->
        <script>
            var body = document.querySelector('body');
            var sidebar = null;
            var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            } else {
                sidebar = 'hidden';
            }
            sidebar_toggle.checked = sidebar === 'visible';
            body.classList.remove('sidebar-visible');
            body.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded affix "><a href="index.html">Introduction</a></li><li class="chapter-item expanded "><a href="installation/index.html"><strong aria-hidden="true">1.</strong> Installation</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="installation/windows.html"><strong aria-hidden="true">1.1.</strong> Windows</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="installation/windows-msvc.html"><strong aria-hidden="true">1.1.1.</strong> MSVC prerequisites</a></li></ol></li><li class="chapter-item expanded "><a href="installation/other.html"><strong aria-hidden="true">1.2.</strong> Other installation methods</a></li><li class="chapter-item expanded "><a href="installation/already-installed-rust.html"><strong aria-hidden="true">1.3.</strong> Already installed Rust?</a></li></ol></li><li class="chapter-item expanded "><a href="concepts/index.html"><strong aria-hidden="true">2.</strong> Concepts</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="concepts/channels.html"><strong aria-hidden="true">2.1.</strong> Channels</a></li><li class="chapter-item expanded "><a href="concepts/toolchains.html"><strong aria-hidden="true">2.2.</strong> Toolchains</a></li><li class="chapter-item expanded "><a href="concepts/components.html"><strong aria-hidden="true">2.3.</strong> Components</a></li><li class="chapter-item expanded "><a href="concepts/profiles.html"><strong aria-hidden="true">2.4.</strong> Profiles</a></li><li class="chapter-item expanded "><a href="concepts/proxies.html"><strong aria-hidden="true">2.5.</strong> Proxies</a></li></ol></li><li class="chapter-item expanded "><a href="basics.html"><strong aria-hidden="true">3.</strong> Basic usage</a></li><li class="chapter-item expanded "><a href="overrides.html" class="active"><strong aria-hidden="true">4.</strong> Overrides</a></li><li class="chapter-item expanded "><a href="cross-compilation.html"><strong aria-hidden="true">5.</strong> Cross-compilation</a></li><li class="chapter-item expanded "><a href="environment-variables.html"><strong aria-hidden="true">6.</strong> Environment variables</a></li><li class="chapter-item expanded "><a href="configuration.html"><strong aria-hidden="true">7.</strong> Configuration</a></li><li class="chapter-item expanded "><a href="network-proxies.html"><strong aria-hidden="true">8.</strong> Network proxies</a></li><li class="chapter-item expanded "><a href="examples.html"><strong aria-hidden="true">9.</strong> Examples</a></li><li class="chapter-item expanded "><a href="security.html"><strong aria-hidden="true">10.</strong> Security</a></li><li class="chapter-item expanded "><a href="faq.html"><strong aria-hidden="true">11.</strong> FAQ</a></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle">
                <div class="sidebar-resize-indicator"></div>
            </div>
        </nav>

        <!-- Track and set sidebar scroll position -->
        <script>
            var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
            sidebarScrollbox.addEventListener('click', function(e) {
                if (e.target.tagName === 'A') {
                    sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
                }
            }, { passive: true });
            var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
            sessionStorage.removeItem('sidebar-scroll');
            if (sidebarScrollTop) {
                // preserve sidebar scroll position when navigating via links within sidebar
                sidebarScrollbox.scrollTop = sidebarScrollTop;
            } else {
                // scroll sidebar to current active section when navigating via "next/previous chapter" buttons
                var activeSection = document.querySelector('#sidebar .active');
                if (activeSection) {
                    activeSection.scrollIntoView({ block: 'center' });
                }
            }
        </script>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky">
                    <div class="left-buttons">
                        <label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </label>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>

                    <h1 class="menu-title">The rustup book</h1>

                    <div class="right-buttons">
                        <a href="print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>
                        <a href="https://github.com/rust-lang/rustup/tree/master/doc/user-guide" title="Git repository" aria-label="Git repository">
                            <i id="git-repository-button" class="fa fa-github"></i>
                        </a>
                        <a href="https://github.com/rust-lang/rustup/edit/master/doc/user-guide/src/overrides.md" title="Suggest an edit" aria-label="Suggest an edit">
                            <i id="git-edit-button" class="fa fa-edit"></i>
                        </a>

                    </div>
                </div>

                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script>
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <h1 id="overrides"><a class="header" href="#overrides">Overrides</a></h1>
<p><code>rustup</code> automatically determines which <a href="concepts/toolchains.html">toolchain</a> to use when one of the
installed commands like <code>rustc</code> is executed. There are several ways to control
and override which toolchain is used:</p>
<ol>
<li>A <a href="#toolchain-override-shorthand">toolchain override shorthand</a> used on the command-line, such as <code>cargo +beta</code>.</li>
<li>The <code>RUSTUP_TOOLCHAIN</code> environment variable.</li>
<li>A <a href="#directory-overrides">directory override</a>, set with the <code>rustup override</code> command.</li>
<li>The <a href="#the-toolchain-file"><code>rust-toolchain.toml</code></a> file.</li>
<li>The <a href="#default-toolchain">default toolchain</a>.</li>
</ol>
<p>The toolchain is chosen in the order listed above, using the first one that is
specified. There is one exception though: directory overrides and the
<code>rust-toolchain.toml</code> file are also preferred by their proximity to the current
directory. That is, these two override methods are discovered by walking up
the directory tree toward the filesystem root, and a <code>rust-toolchain.toml</code> file
that is closer to the current directory will be preferred over a directory
override that is further away.</p>
<p>To verify which toolchain is active, you can use <code>rustup show</code>.</p>
<h2 id="toolchain-override-shorthand"><a class="header" href="#toolchain-override-shorthand">Toolchain override shorthand</a></h2>
<p>The <code>rustup</code> toolchain proxies can be instructed directly to use a specific
toolchain, a convenience for developers who often test different toolchains.
If the first argument to <code>cargo</code>, <code>rustc</code> or other tools in the toolchain
begins with <code>+</code>, it will be interpreted as a <code>rustup</code> toolchain name, and that
toolchain will be preferred, as in</p>
<pre><code class="language-console">cargo +beta test
</code></pre>
<h2 id="directory-overrides"><a class="header" href="#directory-overrides">Directory overrides</a></h2>
<p>Directories can be assigned their own Rust toolchain with <code>rustup override</code>.
When a directory has an override then any time <code>rustc</code> or <code>cargo</code> is run
inside that directory, or one of its child directories, the override toolchain
will be invoked.</p>
<p>To use to a specific nightly for a directory:</p>
<pre><code class="language-console">rustup override set nightly-2014-12-18
</code></pre>
<p>Or a specific stable release:</p>
<pre><code class="language-console">rustup override set 1.0.0
</code></pre>
<p>To see the active toolchain use <code>rustup show</code>. To remove the override and use
the default toolchain again, <code>rustup override unset</code>.</p>
<p>The per-directory overrides are stored in <a href="configuration.html">a configuration file</a> in <code>rustup</code>’s
home directory.</p>
<h2 id="the-toolchain-file"><a class="header" href="#the-toolchain-file">The toolchain file</a></h2>
<p>Some projects find themselves ‘pinned’ to a specific release of Rust and want
this information reflected in their source repository. This is most often the
case for nightly-only software that pins to a revision from the release
archives.</p>
<p>In these cases the toolchain can be named in the project’s directory in a file
called <code>rust-toolchain.toml</code> or <code>rust-toolchain</code>. If both files are present in
a directory, the latter is used for backwards compatibility. The files use the
<a href="https://toml.io/">TOML</a> format and have the following layout:</p>
<pre><code class="language-toml">[toolchain]
channel = "nightly-2020-07-10"
components = [ "rustfmt", "rustc-dev" ]
targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
profile = "minimal"
</code></pre>
<p>The <code>[toolchain]</code> section is mandatory, and at least one property must be
specified. <code>channel</code> and <code>path</code> are mutually exclusive.</p>
<p>For backwards compatibility, <code>rust-toolchain</code> files also support a legacy
format that only contains a toolchain name without any TOML encoding, e.g.
just <code>nightly-2021-01-21</code>. The file has to be encoded in US-ASCII in this case
(if you are on Windows, check the encoding and that it does not start with a
BOM). The legacy format is not available in <code>rust-toolchain.toml</code> files.</p>
<p>If you see the following error (when running <code>rustc</code>, <code>cargo</code> or other command)</p>
<pre><code>error: invalid channel name '[toolchain]' in '/PATH/TO/DIRECTORY/rust-toolchain'
</code></pre>
<p>it means you’re running <code>rustup</code> pre-1.23.0 and trying to interact with a project
that uses the new TOML encoding in the <code>rust-toolchain</code> file. You need to upgrade
<code>rustup</code> to 1.23.0+.</p>
<p>The <code>rust-toolchain.toml</code>/<code>rust-toolchain</code> files are suitable to check in to
source control. If that’s done, <code>Cargo.lock</code> should probably be tracked too if
the toolchain is pinned to a specific release, to avoid potential compatibility
issues with dependencies.</p>
<h3 id="toolchain-file-settings"><a class="header" href="#toolchain-file-settings">Toolchain file settings</a></h3>
<h4 id="channel"><a class="header" href="#channel">channel</a></h4>
<p>The <code>channel</code> setting specifies which <a href="concepts/toolchains.html">toolchain</a> to use. The value is a
string in the following form:</p>
<pre><code>(&lt;channel&gt;[-&lt;date&gt;])|&lt;custom toolchain name&gt;

&lt;channel&gt;       = stable|beta|nightly|&lt;versioned&gt;[-&lt;prerelease&gt;]
&lt;versioned&gt;     = &lt;major.minor&gt;|&lt;major.minor.patch&gt;
&lt;prerelease&gt;    = beta[.&lt;number&gt;]
&lt;date&gt;          = YYYY-MM-DD
</code></pre>
<h4 id="path"><a class="header" href="#path">path</a></h4>
<p>The <code>path</code> setting allows a custom toolchain to be used. The value is an
absolute path string.</p>
<p>Since a <code>path</code> directive directly names a local toolchain, other options
like <code>components</code>, <code>targets</code>, and <code>profile</code> have no effect.</p>
<p><code>channel</code> and <code>path</code> are mutually exclusive, since a <code>path</code> already
points to a specific toolchain.</p>
<h4 id="profile"><a class="header" href="#profile">profile</a></h4>
<p>The <code>profile</code> setting names a group of components to be installed. The
value is a string. The valid options are: <code>minimal</code>, <code>default</code>, and
<code>complete</code>. See <a href="concepts/profiles.html">profiles</a> for details of each.</p>
<p>Note that if not specified, the <code>default</code> profile is not necessarily
used, as a different default profile might have been set with <code>rustup set profile</code>.</p>
<h4 id="components"><a class="header" href="#components">components</a></h4>
<p>The <code>components</code> setting contains a list of additional components to
install. The value is a list of strings. See <a href="concepts/components.html">components</a> for a list of
components. Note that different toolchains may have different components
available.</p>
<p>The components listed here are additive with the current profile.</p>
<h4 id="targets"><a class="header" href="#targets">targets</a></h4>
<p>The <code>targets</code> setting contains a list of platforms to install for
<a href="https://rust-lang.github.io/rustup/cross-compilation.html">cross-compilation</a>. The value is a list of strings.</p>
<p>The host platform is automatically included; the targets listed here are
additive.</p>
<h2 id="default-toolchain"><a class="header" href="#default-toolchain">Default toolchain</a></h2>
<p>If no other overrides are set, the global default toolchain will be used. This
default can be chosen when <code>rustup</code> is <a href="installation/index.html">installed</a>. The <code>rustup default</code>
command can be used to set and query the current default. Run <code>rustup default</code>
without any arguments to print the current default. Specify a toolchain as an
argument to change the default:</p>
<pre><code class="language-console">rustup default nightly-2020-07-27
</code></pre>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                            <a rel="prev" href="basics.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>

                            <a rel="next prefetch" href="cross-compilation.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                    <a rel="prev" href="basics.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>

                    <a rel="next prefetch" href="cross-compilation.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
            </nav>

        </div>




        <script>
            window.playground_copyable = true;
        </script>


        <script src="elasticlunr.min.js"></script>
        <script src="mark.min.js"></script>
        <script src="searcher.js"></script>

        <script src="clipboard.min.js"></script>
        <script src="highlight.js"></script>
        <script src="book.js"></script>

        <!-- Custom JS scripts -->


    </div>
    </body>
</html>
